import { defineStore } from 'pinia';
// import { myStore } from './my';

export const useUserStore = defineStore({
    id: 'user', // id必填，且需要唯一
    state: () => {
        return {
            name: '张三',
            phone: '15688838379'
            // ...getMyInfo() 不能调用actions的方法
            // ...myStore() 不能混入
        };
    },
    actions: {
        updateName(name: string) {
            this.name = name;
        },
        getMyInfo() {
            // const myInfo = myStore();
            // this.name = myInfo.nickName;
            return { name: '白菜' };
        }
    },
    getters: {
        hiddenPhone(state) {
            console.log('getter是有缓存的');

            return state.phone;
        }
        // hiddenPhone2(): string {
        //     console.log('getter是有缓存的');

        //     return this.phone.replace(/^(\d{3})(\d{4})(\d{4})$/, '$1****$3');
        // }
    }
});
